﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AgileRollover.Utility;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;

namespace AgileRollover
{
    //Options class contains all the runtime options for the app

    //Also contains helper methods for commandline input and runtime selection
    //Should probably refactor these methods out of Options and into Program or another class
    public class Options
    {
        private String collectionUri;
        private String username;
        private String password;
        private List<TfsTeam> tfsTeams;
        private String finishedState;

        public Options()
        {
            tfsTeams = new List<TfsTeam>();
        }

        public String CollectionUri
        {
            get { return collectionUri; }
            set { if(value!=null) collectionUri = value; }
        }

        public String Username
        {
            get { return username; }
            set { if (value != null) username = value; }
        }

        public String Password
        {
            get { return password; }
            set { if (value != null) password = value; }
        }

        public Boolean hasTfsTeams()
        {
            if (tfsTeams != null)
            {
                if (tfsTeams.Count > 0)
                {
                    return true;
                }
            }
            return false;
        }
        
        public void addTeam(String teamID)
        {
            if (collectionUri != null)
            {
                TfsTeam newTeam = new TfsTeam();
                newTeam.InitializeFromTFS(username, password, collectionUri, teamID);
                tfsTeams.Add(newTeam);
            }
        }

        public List<TfsTeam> TfsTeams
        {
            get { return tfsTeams; }
            set { if (value != null) tfsTeams = value; }
        }

        public String FinishedState
        {
            get { return finishedState; }
            set { if (value != null) finishedState = value; }
        }

        public Dictionary<string,string> TeamSeparated(string serial)
        {
            string[] separated;
            Dictionary<string,string> retSeparated;
            try
            {
                serial = serial.Replace(", ", ",");
                separated = serial.Split(new Char[] { ',' });
                retSeparated = new Dictionary<string,string>();
                foreach (string line in separated)
                {
                    string[] slash = line.Split('/');
                    retSeparated.Add(slash[0], slash[1]);
                }
                return retSeparated;
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid separator");
                Console.WriteLine(e.Message);
            }
            return null;
        }

    }
}

    
